<!DOCTYPE html>
<html><head>
	    <meta charset="utf-8">
    <title>童老师ThinkPHP交流群：484519446</title>

    <meta name="description" content="Dashboard">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!--Basic Styles-->
    <link href="__admin__/style/bootstrap.css" rel="stylesheet">
    <link href="__admin__/style/font-awesome.css" rel="stylesheet">
    <link href="__admin__/style/weather-icons.css" rel="stylesheet">

    <!--Beyond styles-->
    <link id="beyond-link" href="__admin__/style/beyond.css" rel="stylesheet" type="text/css">
    <link href="__admin__/style/demo.css" rel="stylesheet">
    <link href="__admin__/style/typicons.css" rel="stylesheet">
    <link href="__admin__/style/animate.css" rel="stylesheet">
	<script src="__plus__/ueditor/ueditor.config.js"></script>
	    <script src="__plus__/ueditor/ueditor.all.min.js"></script>
		<script src="__plus__/ueditor/long/zh-cn/zh-cn.js"></script>
		 <style type="text/css">
		    .price{
		        width: 150px;
		        margin-left: 10px;
		        display: inline-block;
		    }
		    .abtn{
		        padding-right: 10px;
		    }
		    </style>
</head>
<body>
	<!-- 头部 -->
    {include file="common/top"}
	<!-- /头部 -->
	
	<div class="main-container container-fluid">
		<div class="page-container">
			<!-- Page Sidebar -->
            {include file="common/left"}
            <!-- /Page Sidebar -->
            <!-- Page Content -->
            <div class="page-content">
                <!-- Page Breadcrumb -->
                <div class="page-breadcrumbs">
                    <ul class="breadcrumb">
                                        <li>
                        <a href="{:url('Index/index')}">系统</a>
                    </li>
                                        <li>
                        <a href="{:url('Goods/lst')}">商品分类管理</a>
                    </li>
                                        <li class="active">修改商品类型</li>
                                        </ul>
                </div>
                <!-- /Page Breadcrumb -->

                <!-- Page Body -->
                <div class="page-body">
                    
<div class="row">
    <div class="col-lg-12 col-sm-12 col-xs-12">
        <div class="widget">
            
            
                    <form class="form-horizontal" role="form" action="" method="post" enctype="multipart/form-data">
                       <input type="hidden" name="id" value="{$goods.id}">
					   <input type="hidden" name="og_thumb" value="{$goods.og_thumb}">
					   <input type="hidden" name="big_thumb" value="{$goods.big_thumb}">
					   <input type="hidden" name="mid_thumb" value="{$goods.mid_thumb}">
					   <input type="hidden" name="sm_thumb" value="{$goods.sm_thumb}">
                        <div class="widget-body">
                                            <div class="widget-main ">
                                                <div class="tabbable">
                                                    <ul class="nav nav-tabs tabs-flat" id="myTab11">
                                                        <li class="active">
                                                            <a data-toggle="tab" href="#baseinfo">
                                                                基本信息
                                                            </a>
                                                        </li>
                                                        <li>
                                                            <a data-toggle="tab" href="#goodsdes">
                                                                描述信息
                                                            </a>
                                                        </li>
														<li>
                                                            <a data-toggle="tab" href="#mbprice">
                                                                会员价格
                                                            </a>
                                                        </li>
														 <li>
                                                            <a data-toggle="tab" href="#goodsattr">
                                                                商品属性
                                                            </a>
                                                        </li>
														<li>
                                                            <a data-toggle="tab" href="#goodsphoto">
                                                                商品相册
                                                            </a>
                                                        </li>
                                                    </ul>
                                                    <div class="tab-content tabs-flat">
                                                       <div id="baseinfo" class="tab-pane in active">
														<div class="form-group">
                                                            <label for="username"  class="col-sm-2 control-label no-padding-right">商品名称</label>
															<div class="col-sm-6">
																<input class="form-control" placeholder="" name="goods_name" value="{$goods.goods_name}" type="text">
															</div>
															 <p class="help-block col-sm-4 red">* 必填</p>
                                                        </div>
														<div class="form-group">
															<label for="username" class="col-sm-2 control-label no-padding-right">推荐位</label>
															<div class="col-sm-6">
																<div class="checkbox">
																	{volist name="goodsRecposRes" id="recpos"}
																		<label style="margin-right: 10px;">
																			<?php
																				if(in_array($recpos['id'],$myGoodsRecposRes)){
																					$checked = 'checked = "checked"';
																				}else{
																					$checked = '';
																				}
																			?>
																			<input <?php echo $checked;?> type="checkbox" name="recpos[]" value="{$recpos.id}" class="colored-blue">
																			<span class="text">{$recpos.rec_name}</span>
																		</label>
																	{/volist}
																</div>
															</div>
														</div>
														<div class="form-group">
														    <label for="username" class="col-sm-2 control-label no-padding-right">商品主图</label>
														        <div class="col-sm-6">
														         <input class="form-control" style="border:none; box-shadow:none;" name="og_thumb" type="file">
																 {if condition="$goods['sm_thumb']"}
																	<img src="__uploads__/{$goods.sm_thumb}" height="30">
																 {else /}
																	暂无缩略图
																 {/if}
														    </div>
														</div>
                                                        <div class="form-group">
                                                            <label for="username"  class="col-sm-2 control-label no-padding-right">上架</label>
                                                        	<div class="col-sm-6">
                                                        		<div class="radio">
																	<label>
																		<input {if condition="$goods['on_sale'] eq 1"} checked="checked"{/if} name="on_sale" type="radio" class="colored-blue" value="1">
																		<span class="text">是</span>
																	</label>
																	<label>
																		<input   {if condition="$goods['on_sale'] eq 0"} checked="checked"{/if} name="on_sale" type="radio" class="colored-blue" value="0">
																		<span class="text">否</span>
																	</label>
																</div>
                                                        	</div>
                                                        </div>
														<div class="form-group">
														    <label for="username"  class="col-sm-2 control-label no-padding-right">所属栏目</label>
															<div class="col-sm-6">
																<select name="category_id">
																<option value="">请选择</option>
																	{volist name="CategoryRes" id="cate"}
																		<option {if condition="$goods['category_id'] eq $cate['id']"}selected="selected"{/if} value="{$cate.id}"><?php echo str_repeat('-', $cate['level']*8)?>{$cate.cate_name}</option>
																	{/volist}
																</select>
															</div>
														</div>
														
														<div class="form-group">
														    <label for="username"  class="col-sm-2 control-label no-padding-right">所属品牌</label>
														    	<div class="col-sm-6">
														    	<select name="brand_id">
														    			<option value="">请选择</option>
														    		{volist name="brandRes" id="brand"}
														    			<option {if condition="$goods['brand_id'] eq $brand['id']"}selected="selected"{/if} value="{$brand.id}">{$brand.brand_name}</option>
														    		{/volist}
														    	</select>
														    </div>
														</div>
														<div class="form-group">
														    <label for="username"  class="col-sm-2 control-label no-padding-right">市场价</label>
															<div class="col-sm-6">
																<input class="form-control" placeholder="" name="markte_price"  value="{$goods.markte_price}" type="text">
															</div>
															 <p class="help-block col-sm-4 red">* 必填</p>
														</div>
														<div class="form-group">
														    <label for="username"  class="col-sm-2 control-label no-padding-right">本店价</label>
															<div class="col-sm-6">
																<input class="form-control" placeholder="" name="shop_price" value="{$goods.shop_price}" type="text">
															</div>
															
														</div>
														<div class="form-group">
														    <label for="username"  class="col-sm-2 control-label no-padding-right">重量</label>
															<div class="col-sm-6">
																<input class="form-control" style="width:300px;display:inline-block;" value="{$goods.goods_weight}" placeholder="" name="goods_weight"  type="text">
																<select name="weight_unit">
																	<option {if condition="$goods['weight_unit'] eq 'Kg'"}selected="selected"{/if} value="kg">kg</option>
																	<option  {if condition="$goods['weight_unit'] eq 'g'"}selected="selected"{/if} value="g">g</option>
																</select>
															</div>
															 <p class="help-block col-sm-4 red">* 必填</p>
														</div>
														</div>
														<div id="goodsdes" class="tab-pane">
														    <textarea name="goods_des" id="goods_des">{$goods.goods_des}</textarea>
														</div>
														<div id="mbprice" class="tab-pane">
															{volist name="mlRes" id="ml"}
															
																<div class="form-group">
																	<label for="username" class="col-sm-2 control-label no-padding-right">{$ml.level_name}</label>
																	<div class="col-sm-6">
																		<input class="form-control" placeholder="" name="mp[{$ml.id}]" value="<?php 
																		if(isset($mpRes[$ml['id']]['mprice']))
																		{
																			echo $mpRes[$ml['id']]['mprice'];
																		}else{
																			echo '';
																		}?>" type="text">
																	</div>
																</div>
															{/volist}
														</div>
														
														<div id="goodsattr" class="tab-pane">
															<div  class="form-group">
															<label for="username" class="col-sm-2 control-label no-padding-right">商品类型</label>
															<div class="col-sm-6">
															<select name="type_id"  {if condition="$goods['type_id'] neq 0"} disabled="disabled" {/if} >
															<option value="0">请选择</option>
														        {volist name="typeRes" id="type"}
														          <option {if condition="$goods['type_id'] eq $type['id']"}selected="selected"{/if} value="{$type.id}">{$type.type_name}</option>
														        {/volist}
														      </select>
															  
														       </div>
														     </div>
														     <div id="attr_list">
														           <!-- 属性显示  -->
															<?php foreach($attrRes as $k => $v): ?>
																<?php if($v['attr_type'] == 1): 
																   $arrRido = explode(',',$v['attr_values']);?>
																   <!--单选-->
																   <?php foreach($gattrRes[$v['id']] as $k0=>$v0):?>
																   <div gaid="<?php echo $v0['id'];?>" class="form-group">
																	   <label class="col-sm-2 control-label no-padding-right"><?php echo $v['attr_name'];?></label>
																	<div class="col-sm-6">
																		
																		<?php if($k0==0){
																			echo '<a onclick="addtr(this);"  href="javascript:;">+</a>'; }
																			else{ echo '<a onclick="addtr(this);"  href="javascript:;">-</a>'; }?>
																  <select name='old_goods_attr[<?php echo $v['id']?>][]'>
																	   		<option value="">请选择</option>
																	   <?php foreach($arrRido as $k1=>$v1): ?>
																	  		 <option <?php if($v1 == $v0['attr_value']){echo 'selected="selected"';}?> value="<?php echo $v1;?>"> <?php echo $v1;?></option>
																	   <?php endforeach;?>
																   </select>
																   <input class="form-control price" placeholder="价格" name="old_attr_price[<?php echo $v0['id'];?>]" type="text" value="<?php echo $v0['attr_price']?>" ></div></div>
																   <?php endforeach;?>
																<?php else:?>
																   <!--唯一-->
																   <?php if(!$v['attr_values']):?>
																   <div   class="form-group"><label class="col-sm-2 control-label no-padding-right"><?php echo $v['attr_name'];?></label>
																	<div class="col-sm-6"><input class="form-control price"  name='old_goods_attr[<?php echo $v['id']?>]' value="<?php echo $gattrRes[$v['id']][0]['attr_value']?>" type="text">
																	<input type="hidden" name="old_attr_price[<?php echo $gattrRes[$v['id']][0]['id'];?>]">
																	</div>
																	</div>
																   <?php else: 
																 	$arrSelect = explode(',',$v['attr_values']);  
																   ?>
																   <div  class="form-group"><label class="col-sm-2 control-label no-padding-right"><?php echo $v['attr_name'];?></label>
																	<div class="col-sm-6">
																   <select name='old_goods_attr[<?php echo $v['id']?>]'>
																	   <option value="">请选择</option>
																	   <?php foreach($arrSelect as $k1=>$v1 ) :?>
																	   <option <?php if($v1 == $gattrRes[$v['id']][0]['attr_value']){echo 'selected="selected"';}?> value="<?php echo $v1;?>"><?php echo $v1;?></option>
																		<?php endforeach;?>
																	</select>
																	<input type="hidden" name="old_attr_price[<?php echo $gattrRes[$v['id']][0]['id'];?>]">
																</div>
															</div>
																	<?php endif; ?>
																<?php endif; ?>
															<?php endforeach;?>

														       </div> 
														   </div>
														




														<div id="goodsphoto" class="tab-pane">
															{volist name="gphotoRes" id="gphoto"}
																<div id="{$gphoto.id}" class="form-group">
																	<label for="username" class="col-sm-2 control-label no-padding-right"></label>
																	<div class="col-sm-6">
																		<a href="#" onclick="delrow(this);">-</a>
																		<img height="30" style="box-shadow: none; display:inline-block;"src="__uploads__/{$gphoto.sm_photo}">
																	</div>
																</div>
															{/volist}
															<div class="form-group">
																<label for="username" class="col-sm-2 control-label no-padding-right"></label>
																<div class="col-sm-6">
																	<a href="#" onclick="addphoto(this);">+</a><input class="form-control" style="border:none; box-shadow:none; width:50%; display:inline-block;" name="goods_photo[]" type="file">
																</div>
															</div>
															
														</div>
													</div>
                                        </div>
                        
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <button type="submit" class="btn btn-default">添加</button>
                            </div>
                        </div>
						</div>
						</div>
                    </form>
               
        </div>
    </div>
</div>

                </div>
                <!-- /Page Body -->
            </div>
            <!-- /Page Content -->
		</div>	
	</div>

	    <!--Basic Scripts-->
    <script src="__admin__/style/jquery_002.js"></script>
    <script src="__admin__/style/bootstrap.js"></script>
    <script src="__admin__/style/jquery.js"></script>
    <!--Beyond Scripts-->
    <script src="__admin__/style/beyond.js"></script>
    
	<script type="text/javascript">
			//实例化编辑器
			//建议使用工厂方法getEditor创建和引用编辑器实例,如果在扣个闭包下引用该编辑器,直接调用UE.getEditor('editor')就能拿到相关的实例
			UE.getEditor('goods_des',{initialFrameWidth:600,initialFrameHeight:400,});
			// <!-- toolbars: [['fullscreen', 'source', 'undo', 'redo','bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript','removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist','selectall', 'cleardoc']] -->
	</script>
	<script type="text/javascript">
		$("select[name=type_id]").change(function(){
			var type_id=$(this).val();
			$.ajax({
				type:"POST",
				url:"{:url('Attr/ajaxGetAttr')}",
				data:{type_id:type_id},
				dataType:"json",
				success:function(data){
					var html="";
					$(data).each(function(k,v){
						 if(v.attr_type == 1){
                        // 单选处理
                        html+="<div class='form-group'>";
                        html+="<label class='col-sm-2 control-label no-padding-right'>"+v.attr_name+"</label>";
                        var attrValuesArr=v.attr_values.split(",");
                        html+="<div class='col-sm-6'><a class='abtn' onclick='addrow(this);' href='#'>[+]</a>";
                        html+="<select name='goods_attr["+v.id+"][]'>";
                        html+="<option value=''>请选择</option>";
                        for(var i=0; i<attrValuesArr.length; i++){
                            html+="<option value='"+attrValuesArr[i]+"'>"+attrValuesArr[i]+"</option>";
                        }
                        html+="</select>";
                        html+="<input class='form-control price' placeholder='价格' name='attr_price[]' type='text'>";
                        html+="</div></div>";

						}else{
							//唯一处理
							if(v.attr_values){
								
								html+="<div class='form-group'>";
								html+="<label class='col-sm-2 control-label no-padding-right'>"+v.attr_name+"</label>";
								var attrValuesArr=v.attr_values.split(",");
								 html+="<div class='col-sm-6'>";
								html +="<select name=goods_attr["+v.id+"]>";
								html +="<option>请选择</option>";
								for(var i=0; i<attrValuesArr.length;i++){
									html += "<option value='"+attrValuesArr[i]+"'>"+attrValuesArr[i]+"</option>";
								}
								html +="</select>";
								html+="</div></div>";
							}else{
								html+="<div class='form-group'>";
								html+="<label class='col-sm-2 control-label no-padding-right'>"+v.attr_name+"</label>";
								
								html+="<div class='col-sm-6'>";
								html+="<input class='form-control price' name=goods_attr["+v.id+"] type='text'>";
								html+="</div></div>";
							}
						}
					});
					$("#attr_list").html(html);
				}
			});
		});
		function delrow(o){
			if(confirm('确定要删除图片吗?')){
				var div = $(o).parent().parent();
				var id = div.attr('id');
				$.ajax({
					type:"POST",
					data:{id : id},
					url:"{:url('Goods/ajaxdelpic')}",
					success:function(data){
						if(data==1){
							div.remove();
						}else {
							alert('删除失败');
						}
					}
				});
			}
		}
		function addrow(o){
        
        
    }
		function addphoto(o){
			var div=$(o).parent().parent();
			if($(o).html() == '+'){
				var newdiv = div.clone();
				newdiv.find('a').html('-');
				div.after(newdiv);
			}else{
				div.remove();
			}
		}
		function addtr(o){
			var div=$(o).parent().parent();
		if($(o).html() == '+'){
				var newdiv = div.clone();
				newdiv.find('a').html('-');
				//修改old_attr_price[] 为 attr_price[]
				newdiv.find(':text').attr('name','attr_price[]');
				//修改old_goods_attr[8][] 为 goods_attr[8][]
				var sel = newdiv.find('select');
				var oldname=sel.attr('name');
				var newname=oldname.replace('old_','');
				sel.attr('name',newname);
				
				div.after(newdiv);
        }else{
            if(confirm('确定要删除该属性吗？')){
                var div=$(o).parent().parent();
                var gaid=div.attr('gaid');
				
                $.ajax({
                    type:"POST",
                    data:{gaid:gaid},
                    url:"{:url('GoodAttr/ajaxdelga')}",
                    success:function(data){
                       if(data==1){
                            div.remove(); 
                        }else{
                            alert('删除失败！');
                        }
                    }
                });  
            }
        }
                   }
	</script>

</body></html>